// list
// Created by FanGccU on 2025/6/22.
// 双向链表

#include <iostream>
#include <list>
using namespace std;

/**
 * 插入和移除
 */
void func1() {
    list<int> l = {1, 2, 3};
    // 向尾部插入
    l.push_back(4);
    l.push_back(5);
    // 向头部插入
    l.push_front(0);

    cout << "one value:\t";
    for (list<int>::iterator it = l.begin(); it != l.end(); ++it) {
        cout << *it << "\t";
    }
    cout << endl;

    list<int>::iterator it = l.begin(); // 获取集合中首个元素的迭代器
    advance(it, 2); // 移动迭代器到第三个元素。2
    l.insert(it, 22); // 在迭代器元素前面插入22


    cout << "two value:\t";
    for (list<int>::iterator it = l.begin(); it != l.end(); ++it) {
        cout << *it << "\t";
    }
    cout << endl;

    l.erase(it); // 移除当前迭代器选中的元素

    cout << "final value:\t";
    for (list<int>::iterator it = l.begin(); it != l.end(); ++it) {
        cout << *it << "\t";
    }
}

void func2() {
    list<int> l1 = {2, 8, 4, 3, 5};
    list<int> l2 = {1, 9, 0, 4, 2};
    // 和并
    l1.merge(l2);
    // 排序
    l1.sort();
    cout << "marge sort value:\t";
    for (int i: l1) {
        cout << i << "\t";
    }
    cout << endl;

    // 去重
    l1.unique();

    cout << "unique value:\t";
    for (int i: l1) {
        cout << i << "\t";
    }
    cout << endl;

    // 顺序反转
    l1.reverse();

    cout << "reverse value:\t";
    for (int i: l1) {
        cout << i << "\t";
    }
    cout << endl;
}


int main(int argc, char *argv[]) {
    // func1();
    func2();
}
